﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OMModel;
using System.IO;

namespace OMUtility
{
    public class DataAccess
    {
        public static List<NormalProductInfo> GetProductsFromFile(string file)
        {
            List<NormalProductInfo> list = new List<NormalProductInfo>();
            using (StreamReader sr = new StreamReader(file, Encoding.GetEncoding("gb2312")))
            {
                string line = null;
                NormalProductInfo tmp;
                while((line = sr.ReadLine()) != null){
                    tmp = new NormalProductInfo();
                    string[] arr = line.Split(new char[]{','});
                    tmp.ProductId = arr[0];
                    tmp.Name = arr[1];
                    tmp.Rate = Int32.Parse(arr[2]);
                    tmp.Price = Double.Parse(arr[3]);
                    tmp.Type = arr[4];
                    tmp.Points =long.Parse(arr[5]);
                    tmp.ImgName = arr[6];
                    tmp.Desc = arr[7];
                    list.Add(tmp);
                }
            }

            return list;
        }
    }
}
